<!DOCTYPE html>
<html>
    <head>
        <title>db connect test</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style type="text/css">
            body, td { font-size:12px; color:#333;}
            table {border:solid 1px #CCC; border-bottom: none; border-right:none;}
            td, th { border:solid 1px #CCC; border-top:none; border-left:none; padding:3px;}
        </style>
    </head>
    <body>
        <?php
        /*
         * To change this license header, choose License Headers in Project Properties.
         * To change this template file, choose Tools | Templates
         * and open the template in the editor.
         */

        $dbconf = array(
            'db_host' => '127.0.0.1', // 数据库服务器
            'db_user' => 'xcall', // 数据库用户名
            'db_pwd' => 'root!@#xcall098)(*Admin%^&', // 数据库密码
            'db_name' => 'db_siluntang_v1', // 数据库名称
        );
        mysql_connect($dbconf['db_host'], $dbconf['db_user'], $dbconf['db_pwd']) or die(mysql_error());
        mysql_select_db('mysql') or die(mysql_error());
        mysql_query('set names utf8');
        $result = mysql_query('show tables');
        $atables = array();
        while (false !== ($row = mysql_fetch_array($result, MYSQL_NUM))) {
            $atables[] = $row[0];
        }
        sort($atables);
        foreach ($atables as $table) {
            if (0 === strpos($table, 'pre_')) {
                continue;
            }
            $iswxtable = (0 === strpos($table, 'send'));
            echo '<h3', ($iswxtable ? ' style="color:#F00"' : ''), '>', $table, '</h3>';
            echo '<table>';
            $sql = 'select * from ' . $table . ' limit 10';
            if ($iswxtable) {
                $sql = 'select * from ' . $table . ' order by id desc';
            }
            $resultdata = mysql_query($sql);
            $head = false;
            while (false !== ($row2 = mysql_fetch_assoc($resultdata))) {
                if (!$head) {
                    foreach ($row2 as $field => $value) {
                        echo '<th>', $field, '</th>';
                    }
                    $head = true;
                }
                echo '<tr>';
                foreach ($row2 as $field => $value) {
                    echo '<td>', $value, '</td>';
                }
                echo '</tr>';
            }
            echo '</table>';
        }
        ?>
    </body>
</html>